/**
 * 在线问答
 * 校验规则
 */
const { query, checkSchema } = require("express-validator");

// 通用校验规则
const commonValidation = {
  question: {
    in: ["body"],
    notEmpty: true,
    trim: true,
    errorMessage: "请输入问题",
  },
  answer: {
    in: ["body"],
    notEmpty: true,
    trim: true,
    errorMessage: "请输入答案",
  },
};

const newsValidation = {
  // 列表
  list_validation: [query("page").default(1).toInt().isInt({ min: 1 }).withMessage("请输入页码"), query("limit").default(10).toInt().isInt({ min: 1 }).withMessage("请输入每页数量")],
  // 添加
  add_validation: checkSchema({ ...commonValidation }),
  // 修改
  update_validation: checkSchema({
    qna_id: {
      in: ["body"],
      notEmpty: true,
      trim: true,
      errorMessage: "请输入问答ID",
    },
    ...commonValidation,
  }),
  // 删除
  delete_validation: checkSchema({
    qna_id: {
      in: ["query"],
      notEmpty: true,
      trim: true,
      errorMessage: "请输入问答ID",
    },
  }),
};

module.exports = newsValidation;
